// 导入axios
import axios from 'axios'
const http = axios.create({
  // baseURL: import.meta.env.VITE_BASE_URL,
  baseURL: import.meta.env.VITE_BASE_URL,
  timeout: 3000, //请求超时设置，单位ms
})
// 请求拦截器
http.interceptors.request.use(
  (config) => {
    //判断token是否存在
    if (localStorage.getItem('authorization')) {
      //在请求发出去之前,加上统一的header头
      // const A = localStorage.getItem(authorization.token)
      config.headers.Authorization = 'Bearer ' + localStorage.getItem('authorization')
    }
    return config
  },
  (error) => {
    return Promise.reject(error)
  }
)
// 响应拦截器
http.interceptors.response.use(
  (response) => response.data,
  (error) => Promise.reject(error)
)
//导出我们建立的axios实例模块
export default http
